package com.controller;

import com.util.QiNiuYunUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import living.com.domain.QiNiuTokenResult;
import living.com.result.ApiResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2022/2/11 17:54
 */
@RestController
@Api(tags = "评论文件请求处理")
@RequiredArgsConstructor
public class CommentFileController {
    private final QiNiuYunUtils qiNiuYunUtils;
    @ApiOperation("评论图片上传凭证获取")
    @PostMapping("/comment_pics")
    public ApiResult<List<QiNiuTokenResult>> getUploadPicsToken(@ApiParam("上传图片的数量")@RequestParam(defaultValue = "1") Integer pic_sum)
    {
        try {
            return ApiResult.success(qiNiuYunUtils.getTokenResults(pic_sum, QiNiuYunUtils.File_Type.COMMENT_IMG));
        } catch (Exception e) {
            throw new IllegalArgumentException("七牛云文件上传凭证获取出错");
        }
    }

    @ApiOperation("评论视频上传凭证获取")
    @PostMapping("/comment_videos")
    public ApiResult<QiNiuTokenResult> getUploadVideoToken()
    {
        try {
            return ApiResult.success(qiNiuYunUtils.getTokenResult(QiNiuYunUtils.File_Type.COMMENT_VIDEO.getFilePrefix()));
        } catch (Exception e) {
            throw new IllegalArgumentException("七牛云文件上传凭证获取出错");
        }
    }
}
